package com.lmonkey.servlet.my;

import com.lmonkey.servic.USERDao;
import com.lmonkey.shop.USER;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/shangc/regrxx")
public class Regrxx extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");

        //获取数据
        String yname = request.getParameter("yname");
        String pass = request.getParameter("pass");
        String name = request.getParameter("username");
        String birthday = request.getParameter("birthday");
        String sex = request.getParameter("sex");

        //进行修改
        int count = 0;
        count =  USERDao.updateDate(yname,name,birthday,sex);

        //数据库中查找数据
        HttpSession session = request.getSession();
        USER user = USERDao.selectAdmin(name,pass);
        session.setAttribute("name",user);
        session.setAttribute("isLogin","1");

        if (count>0){
            response.sendRedirect("mygrxxselect");
        }else{
            PrintWriter out = response.getWriter();
            out.println("<script>alert('保存失败');location.href='mygrxxselect';</script>");
            out.close();
        }
    }
}
